package dev.alm.alertagentservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import dev.alm.alertagentservice.bean.Alert;
import dev.alm.alertagentservice.mapper.AlertMapper;
import dev.alm.alertagentservice.service.AlertService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AlertServiceImpl implements AlertService {

    @Resource
    private AlertMapper alertMapper;

    @Override
    public List<Alert> getAlertList(String handler) {
        QueryWrapper<Alert> wrapper = new QueryWrapper<>();
        wrapper.eq("current_handler", handler);
        return alertMapper.selectList(wrapper);
    }

    @Override
    public Long getAlertCountByHandler(String handler) {
        QueryWrapper<Alert> wrapper = new QueryWrapper<>();
        wrapper.eq("current_handler", handler);
        return alertMapper.selectCount(wrapper);
    }

    @Override
    public Boolean updateAlert(Alert alert) {
        return alertMapper.updateById(alert) > 0;
    }

    @Override
    public Alert getAlertById(Long id) {
        return alertMapper.selectById(id);
    }
}
